'use client';
import type { FC } from 'react';
import React, { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { useAppContext } from '@/context/app-context';

export type IAppDetail = {
  children: React.ReactNode;
};

const AppDetail: FC<IAppDetail> = ({ children }) => {
  const router = useNavigate();
  const { isCurrentWorkspaceDatasetOperator } = useAppContext();

  useEffect(() => {
    if (isCurrentWorkspaceDatasetOperator) return router('/datasets', { replace: true });
  }, [isCurrentWorkspaceDatasetOperator]);

  return <>{children}</>;
};

export default React.memo(AppDetail);
